#include <iostream>

using namespace std;

typedef long long LL;

int n, k, last;
LL res;

int main()
{
	cin >> n >> k;
	
	for (int i = 0; i < n; i ++ )
	{
		int v;
		cin >> v;
		int t = max(0, v + last - k);
//		if (t < 0) t = 0;
		v -= t;
		res += t;
		last = v;
	}
	
	cout << res << endl;
	
	return 0;
} 
